package com.masterclient.app.modules.income.adapter;

import android.content.Context;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.modules.income.dealer.model.DealerBankCardBean;
import java.util.List;

public class SelectBankCardAdapter extends BaseQuickAdapter<DealerBankCardBean, BaseViewHolder> {

    private Context mContext;
    private List<DealerBankCardBean> list;
    private int type = 1; //1:有添加按钮 2：无添加按钮
    private String bankCardCertId;

    public SelectBankCardAdapter(Context mContext, List<DealerBankCardBean> list,String bankCardCertId) {
        super(R.layout.item_select_card);
        this.mContext = mContext;
        this.list = list;
        this.bankCardCertId = bankCardCertId;
    }

    public void setType(int type) {
        this.type = type;
    }


    @Override
    protected void convert(BaseViewHolder helper, DealerBankCardBean item) {
        helper.addOnClickListener(R.id.view_item);
        helper.setText(R.id.tv_bank_name, item.bankShort);
        helper.setText(R.id.tv_bank_code, item.card);

        if (type == 1) {
            if (helper.getLayoutPosition() == list.size() - 1) {
                helper.setGone(R.id.tv_bank_code, false);
                helper.setText(R.id.tv_bank_name, "添加银行卡");
                helper.setImageResource(R.id.iv_bank, R.mipmap.icon_add_bank_card);
                helper.setImageResource(R.id.iv_check, R.mipmap.icon_arrow_of_bank_card);
            } else {
                helper.setGone(R.id.tv_bank_code, true);
                ViewTransformUtil.glideImageView(mContext, item.cardBg, helper.getView(R.id.iv_bank), R.mipmap.user_head_default_icon);
                if (bankCardCertId.equals(item.bankcardCertId)) {
                    helper.setImageResource(R.id.iv_check, R.mipmap.icon_bank_card_checked);
                } else {
                    helper.setImageResource(R.id.iv_check, R.mipmap.icon_bank_card_check);
                }
            }
        } else {
            helper.setGone(R.id.tv_bank_code, true);
            ViewTransformUtil.glideImageView(mContext, item.cardBg, helper.getView(R.id.iv_bank), R.mipmap.user_head_default_icon);
            if (bankCardCertId.equals(item.bankcardCertId)) {
                helper.setImageResource(R.id.iv_check, R.mipmap.icon_bank_card_checked);
            } else {
                helper.setImageResource(R.id.iv_check, R.mipmap.icon_bank_card_check);
            }
        }
    }
}
